<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>2018/11/30</title>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
    <!--好的代码像粥一样,是得用时间和精力熬的。-->
</head>
<body>
<input type="text" placeholder="username" id="username"><br>
<input type="text" placeholder="password" id="password"><br>
<button id="login">login</button>
<button id="test">test</button>
<button id="unlogin">unlogin</button>
</body>
<script>
    var username = document.getElementById('username');
    var password = document.getElementById('password');
    var login = document.getElementById('login');
    var test = document.getElementById('test');
    var unlogin = document.getElementById('unlogin');
    window.onload = function () {
        login.onclick = function () {
            var usernameValue = username.value;
            var passwordValue = password.value;
            $.ajax({
                url:'http://localhost:8080/login',
                method: 'get',
                data: {
                    username: usernameValue,
                    password: passwordValue
                },
                success: function (data) {
                    console.log(data);
                },
                fail: function (error) {
                    console.log(error);
                }
            })
        }
        test.onclick = function () {
            $.ajax({
                url:'http://localhost:8080/test',
                method: 'get',
                success: function (data) {
                    console.log(data);
                },
                fail: function (error) {
                    console.log(error);
                }
            })
        }
        unlogin.onclick = function () {
            $.ajax({
                url:'http://localhost:8080/unlogin',
                method: 'get',
                success: function (data) {
                    console.log(data);
                },
                fail: function (error) {
                    console.log(error);
                }
            })
        }
    }
</script>
</html>